package com.sky.service.impl;

import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.mapper.DishFlavorMapper;
import com.sky.mapper.DishMapper;
import com.sky.mapper.UserDishMapper;
import com.sky.mapper.UserMapper;
import com.sky.service.UserDishService;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserDishServiceImpl implements UserDishService {

    @Autowired
    private UserDishMapper userDishMapper;
    @Autowired
    private DishFlavorMapper dishFlavorMapper;
    @Autowired
    private DishMapper dishMapper;


    @Override
    public List<DishVO> selectByCategoryId(Integer categoryId) {

        List<DishVO> dishVOList = userDishMapper.selectByCategoryId(categoryId);

        for (DishVO dishVO : dishVOList) {
            Long id = dishVO.getId();
            List<DishFlavor> dishFlavors = dishFlavorMapper.selectByDishId(id);
            dishVO.setFlavors(dishFlavors);
        }
        return dishVOList;

    }
}
